FROM golang:latest as builder

# 配置代理
ENV GOPROXY https://mirrors.aliyun.com/goproxy/
# 设置go缓存生成镜像在Dockerfile所在目录执行推送
ENV GO111MODULE=on
# 设置编码格式
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
# go缓存
WORKDIR /root/myDemo/group/service_address
# 增加所有的项目到该工作路径下
ADD . .

Run go mod download
#运行程序
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o final show.go

# 解决镜像太大的问题
FROM alpine:latest
# 安装 /bin/bash 方便调试
RUN echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main/" > /etc/apk/repositories
RUN apk update \
        && apk upgrade \
        && apk add --no-cache bash \
        bash-doc \
        bash-completion \
        && rm -rf /var/cache/apk/* \
        && /bin/bash
# 安装证书 解决http请求
RUN apk add --update ca-certificates
RUN update-ca-certificates

# 统一亚洲时区
ENV TZ=Asia/Beijing
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezon
# 设置目录
WORKDIR /root/
RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
# 将register文件从“builder”中拷贝到本级的当前目录
COPY --from=builder   /root/myDemo/group/service_address/final .

# 暴露端口
EXPOSE 3357

# 项目默认启动命令
ENTRYPOINT ["./final"]
